﻿using System;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using BusinessLogic;

public partial class Error : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.IsAuthenticated)
        {
            HyperLink hlEditProfile = LoginView1.FindControl("hlEditProfile") as HyperLink;
            hlEditProfile.NavigateUrl =
                "~/Private/EditProfile.aspx?" + QueryStringConstants.Username
                + "=" + User.Identity.Name;

            try
            {
                if (Roles.IsUserInRole(Constants.Roles.Admin))
                {
                    pnlAdministartion.Visible = true;
                }
            }
            catch (SqlException) //probably sql server is down
            {
                pnlAdministartion.Visible = false;
            }
        }

        hlEnglish.NavigateUrl = "~/Main.aspx?" + QueryStringConstants.Tag + "=english";
        hlBulgarian.NavigateUrl = "~/Main.aspx?" + QueryStringConstants.Tag + "=bulgarian";

        lbErrorMessage.Text = (string)(Session[Constants.Session.ErrorMessage] ?? "Unable to get error information");
        Session.Remove(Constants.Session.ErrorMessage);
    }

    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        Cache.Remove(Constants.Cache.Users);
    }
}
